﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BoletoElectronicoDesktop.Facturacion
{
    public partial class FormSeleccionarBeneficiario : Form
    {
        public string idbeneficiario;
        public FormSeleccionarBeneficiario()
        {
            InitializeComponent();
        }

        private void btnLimpiar_Click(object sender, EventArgs e)
        {
            txtRazonSocial.Text = "";
            cbRubro.Text = "";
            txtCalle.Text = "";
            txtNum.Text = "";
            txtDepto.Text = "";
            txtPiso.Text = "";
            dataGridView1.DataSource = null;
            
        }

        private void SeleccionarBeneficiario_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
        }

        private void txtNum_KeyPress(object sender, KeyPressEventArgs e)
        {
            Funciones.validarNumero(e);
        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {
            string razonSocial;
            string rubro;
            string calle;
            string numerodireccion;
            string piso;
            string depto;
            razonSocial = txtRazonSocial.Text;
            calle = txtCalle.Text;
            numerodireccion = txtNum.Text;
            piso = txtPiso.Text;
            depto = txtDepto.Text;

            if (cbRubro.Text == "")
                rubro = "";
            else
                rubro = cbRubro.SelectedValue.ToString();

            DataTable dt = FacturacionDAO.ObtenerBeneficiariosHabilitados(razonSocial, rubro, calle, numerodireccion, piso, depto);
            dataGridView1.DataSource = dt;

        }

        private void cbRubro_Click(object sender, EventArgs e)
        {
            //cargo las rubros en el ComboBox
            DataTable rubros = BeneficiarioDAO.ObtenerRubros();
            cbRubro.DataSource = rubros;
            cbRubro.DisplayMember = "DescripcionRubro";
            cbRubro.ValueMember = "IdRubro";
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //cargo la variable para pasarsela al otro formulario
            idbeneficiario = dataGridView1.CurrentRow.Cells["BeneficiarioID"].Value.ToString();

            //cierro el formulario
            Close();
        }
        

        
    }
}
